OrderBy(TSource, TKey) Method (ParallelQuery(TSource), Func(TSource, TKey))

Task Parallel System.Threading

Sorts in parallel the elements of a sequence in ascending order according to a key.

Namespace:  System.Linq
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function OrderBy(Of TSource, TKey) ( _
	source As ParallelQuery(Of TSource), _
	keySelector As Func(Of TSource, TKey) _
) As OrderedParallelQuery(Of TSource)
C#
public static OrderedParallelQuery<TSource> OrderBy<TSource, TKey>(
	ParallelQuery<TSource> source,
	Func<TSource, TKey> keySelector
)

Parameters

source
Type: System.Linq..::.ParallelQuery<(Of <(TSource>)>)
A sequence of values to order.
keySelector
Type: System..::.Func<(Of <(TSource, TKey>)>)
A function to extract a key from an element.

Type Parameters

TSource
The type of elements of source.
TKey
The type of the key returned by keySelector.

Return Value

An OrderedParallelQuery{TSource} whose elements are sorted according to a key.

Remarks

In contrast to the sequential implementation, this is not a stable sort. To achieve a stable sort, change a query of the form:
 Copy Code
var ordered = source.OrderBy((e) => e.k);
to instead be formed as:
 Copy Code
var ordered = source.Select((e,i) => new { E=e, I=i }).OrderBy((v) => v.i).Select((v) => v.e);

Exceptions

ExceptionCondition
System..::.ArgumentNullException source or keySelector is a null reference (Nothing in Visual Basic).

See Also